package com.cloud.pole.rpc;

import com.ace.cache.annotation.Cache;
import com.cloud.pole.admin.service.AuthService;
import com.cloud.pole.admin.service.PermissionService;
import com.cloud.pole.api.admin.AdminUserApi;
import com.cloud.pole.api.permission.PermissionApi;
import com.cloud.pole.api.user.BaseUserApi;
import com.cloud.pole.common.util.jwt.JWTInfo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * ${DESCRIPTION}
 *
 * @author wanghaobin
 * @create 2017-06-21 8:15
 */
@RestController
@RequestMapping("api")
public class AdminUserRest {
    @Autowired
    private PermissionService permissionService;

    @Autowired
    private AuthService authService;

    @Cache(key="permission")
    @RequestMapping(value = "/permissions", method = RequestMethod.GET)
    public @ResponseBody List<PermissionApi> getAllPermission(){
        return permissionService.getAllPermission();
    }

    @Cache(key="permission:u{1}")
    @RequestMapping(value = "/user/un/{username}/permissions", method = RequestMethod.GET)
    public @ResponseBody List<PermissionApi> getPermissionByUsername(@PathVariable("username") String username){
        return permissionService.getPermissionByUsername(username);
    }

    /**
     * 检测用户状态，根据token
     * @param jwtInfo
     * @param token
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/user/validate", method = RequestMethod.GET)
    public @ResponseBody boolean validate(String token) throws Exception{
        return authService.validate(token);
    }
}
